package com.ky.manage.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ky.manage.R;
import com.ky.manage.model.response.OutdoorMendListResp;
import com.ky.manage.utils.Spanny;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 户外整改记录 tab adapter
 */
public class OutdoorModifyTabAdapter extends BaseQuickAdapter<OutdoorMendListResp.OutdoorMendInfo, BaseViewHolder> {
    private List<OutdoorMendListResp.OutdoorMendInfo> list;
    private Context context;

    public OutdoorModifyTabAdapter(Context context, int layoutId, List<OutdoorMendListResp.OutdoorMendInfo> list) {
        super(layoutId, list);
        this.list = list;
        this.context = context;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder , OutdoorMendListResp.OutdoorMendInfo outdoorMendInfo) {
        TextView lineNameTv = baseViewHolder.getView(R.id.line_name_tv);
        TextView checkTimeTv = baseViewHolder.getView(R.id.last_check_time_tv);
        TextView checkStateTv = baseViewHolder.getView(R.id.last_check_state_tv);
        TextView importCheckStateTv = baseViewHolder.getView(R.id.import_check_state_tv);
        if (null == outdoorMendInfo) {
            return;
        }
        lineNameTv.setText(outdoorMendInfo.lineName);
        checkTimeTv.setText("上次检修时间：" + outdoorMendInfo.finishTime);
        //检修结果：0合格，1不合格
        checkStateTv.setText(getCheckResult(outdoorMendInfo));
        //是否重点巡检线路（0是， 1否）
        importCheckStateTv.setText("重点检修线路：" + ("0".equals(outdoorMendInfo.isEmphasis) ? "是" : "否"));
    }

    private Spanny getCheckResult(OutdoorMendListResp.OutdoorMendInfo outdoorMendInfo) {
        Spanny spanny = new Spanny("上次检修结果：");
        if ("1".equals(outdoorMendInfo.checkResult)) {
            //检修结果：0合格，1不合格
            spanny.append("不合格", new ForegroundColorSpan(Color.parseColor("#D60000")));
        } else {
            spanny.append("合格", new ForegroundColorSpan(Color.parseColor("#00D619")));
        }
        return spanny;
    }
}
